package Interfaz.Recursos;


import java.awt.*;  
import javax.swing.*;  


import java.awt.event.*;  
   
public class ImageButton extends JPanel  
{  
        
        private static final long serialVersionUID = 1L;
        Image image = null;
        Image rollOut = null;
        Image rollOver = null;
        
        public ImageButton(String path, String pathOver){  
                super();  
                Image img1 = (new ImageIcon(getClass().getResource(path))).getImage();
                Image roll = (new ImageIcon(getClass().getResource(pathOver))).getImage();
                this.image = img1;
                this.rollOut = img1;
                this.rollOver = roll;
                addMouseListener(new MouseAdapter() {

                        public void mouseEntered(MouseEvent arg0) {
                                setImageRollOver();
                        }
                });
                
                addMouseListener(new MouseAdapter() {

                        public void mouseExited(MouseEvent e) {
                                setImageRollOut();
                        }
                });
        }  
           
        
        public Dimension getPreferredSize(){  
                if (image!=null){  
                        return new Dimension(image.getWidth(this),image.getHeight(this));  
                }else{  
                        return new Dimension(120,80);  
                }  
        }
        
        public void setImageRollOver(){
                this.image = this.rollOver;
                repaint();
        }
        
        public void setImageRollOut(){
                this.image = this.rollOut;
                repaint();
        }
           
        public void paintComponent(Graphics g){   
                Graphics2D g2D = (Graphics2D)g;   
                if (image!=null){  
                        g2D.drawImage(image,0,0,getWidth(),getHeight(),this);  
                };  
        }  
        
           
}//end   